package com.vogue.supplymall.shop.domain.service.impl;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.vogue.ssm.database.dao.BaseDao;
import com.vogue.supplymall.shop.domain.dao.ProductAttrvalueDao;
import com.vogue.supplymall.shop.domain.model.ProductAttrvalue;
import com.vogue.supplymall.shop.domain.service.ProductAttrvalueService;
/**
 * The type ProductAttrvalue service.
 *
 * @aouthor: gzl
 * @create: 2017 -12-01
 */
@Service("productAttrvalueService")
public class ProductAttrvalueServiceImp extends BaseServiceImpl<ProductAttrvalue, Long> implements ProductAttrvalueService {

	@Resource
	private ProductAttrvalueDao productAttrvalueDao;
	
	public ProductAttrvalueServiceImp(BaseDao<ProductAttrvalue, Long> baseDao) {
		super(baseDao);
		// TODO Auto-generated constructor stub
	}

	@Override
	public ProductAttrvalue findProductAttrvalueBySTMP(Long sysCodeId, int typeId, String matchId,
			Long productId) {
		ProductAttrvalue pa=new ProductAttrvalue();
		
		List<ProductAttrvalue> list=productAttrvalueDao.findProductAttrvalueBySTMP(sysCodeId, typeId, matchId, productId);
		if(list.size()>0&&list.get(0)!=null) {
			pa=list.get(0);
		}		
		
		return pa;
	}

	@Override
	public String findMatchIdByAttrplanId(Long attrplanId) {
		String matchIds="";
		
		List<Map<String, Object>> list=productAttrvalueDao.findMatchIdByAttrplanId(attrplanId);		
		for(Map<String, Object> map:list) {
			matchIds+=map.get("matchid");
		}
		
		return matchIds;
	}

	@Override
	public List<Long> findIdBySPM(Long syscodeId, Long productId, String ids) {
		String matchIds="";
		List<Long> idsList=new ArrayList<>();
		
		String[] idAr=ids.split(",");		
		for(int i=0;i<idAr.length;i++) {
			matchIds+="'"+idAr[i]+"',";
		}
		matchIds=matchIds.substring(0,matchIds.length()-1);
		
		List<Map<String, Object>> list=productAttrvalueDao.findIdBySPM(syscodeId, productId, matchIds);
		if(list.size()>0&&list.get(0)!=null) {
			for(Map<String, Object> map:list) {
				Long id=Long.valueOf(map.get("id").toString());
				idsList.add(id);
			}
		}
		
		return idsList;
	}
	
 

}
